<route lang="yaml">
meta:
  title: 雪崩巨量配置
</route>

<script lang="ts" setup>
import { saveCacheFromObject } from '@/utils/fs'
import {ElNotification} from "element-plus";
import {useXueBengStore} from "@/store/modules/xuebeng.ts";

const xueBengStore = useXueBengStore()

const xueBengConfig = ref({
  phone: '',
  password: '',
})

onMounted(() => {
  const cacheConfig = localStorage.xueBengConfig
  if (cacheConfig) {
    const config = JSON.parse(cacheConfig)
    console.log(config)
    xueBengConfig.value.phone = config.phone
    xueBengConfig.value.password = config.password
  }
})

function saveConfig() {
  saveCacheFromObject('xueBengConfig', xueBengConfig.value)
  xueBengStore.login({
    type: 1,
    phone: xueBengConfig.value.phone,
    password: xueBengConfig.value.password,
  })
}

function clearConfig() {
  xueBengConfig.value = { phone: '', password: '' }
  ElNotification({
    title: '操作成功',
    message: '配置已清空',
    type: 'success',
  })
}

</script>

<template>
  <div>
    <FaPageHeader>
      <template #title>
        <div class="flex items-center gap-4">
          ❄️雪崩巨量配置❄️
        </div>
      </template>
      <template #description>
        <div class="text-sm/6">
          <div>
            功能：（非必填）如果需要在本软件进行雪崩巨量的关键字申请及新文拉取，则必须填写，否则无法使用
          </div>
        </div>
      </template>
    </FaPageHeader>
    <FaPageMain>
      <el-form :model="xueBengConfig" label-width="auto" size="large">
        <el-form-item label="账号">
          <el-input v-model="xueBengConfig.phone" style="max-width: 600px;" />
        </el-form-item>
        <el-form-item label="密码">
          <el-input v-model="xueBengConfig.password" style="max-width: 600px;" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="saveConfig">
            保存配置
          </el-button>
          <el-button type="danger" @click="clearConfig">
            重置配置
          </el-button>
        </el-form-item>
      </el-form>
    </FaPageMain>
  </div>
</template>
